#pragma warning(disable:4786)
#pragma warning(disable:4503)

#include <string>
#include <iostream>
#include <vector>
#include <algorithm>

#include <constant.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>

#include "ast_ami.h"
#include "ast_peg.h"

using namespace std;

ast_ami::ast_ami()
{
}
ast_ami::~ast_ami()
{
}
void ast_ami::line_print_dbg( char * aFmt, ... )
{
    va_list sAp;
    va_start( sAp, aFmt );
    vprintf( aFmt, sAp);
    va_end( sAp );
}

ast_ami * ast_ami::parse( char * sCommand )
{
   PBYTE   tmp,start;
   PBYTE   msgStartPtr;
   BYTE    tbuff[32];
   
   C c;
   tmp = (PBYTE)sCommand;
   
   cout << "["<< __FILE__<<" "<<__LINE__<<"] "<<sCommand<< endl;
   
   if( event_f::Matches(tmp,&c,start) )
   {
      memset(s_event, 0, 32);
      memcpy(s_event, start+7, (tmp-start -7-2));
      line_print_dbg("[%s %d]Event: %s\n",__FILE__,__LINE__, s_event);
   }
   else
   {
      tmp = (PBYTE)sCommand;
      if( response_f::Matches( tmp,&c, start ) )
      {
         memset(s_response, 0, 32); 
         memcpy(s_response, start+9, (tmp-start-11));
         line_print_dbg("[%s %d]Response: %s\n",
                     __FILE__,__LINE__, s_response);
      }
   }
   
   msgStartPtr = tmp;
   if( channel_f::Matches(tmp,&c, start) )
   {
      memset(s_channel, 0, 32); 
      memcpy(s_channel, start+9, (tmp-start-11));
      line_print_dbg("[%s %d]Channel: %s\n",
                     __FILE__,__LINE__, s_channel);
   }
   
   msgStartPtr = tmp;
   if( flags_f::Matches(tmp,&c, start) )
   {
      memset(s_flags, 0, 32); 
      memcpy(s_flags, start+16, (tmp-start-18));
      line_print_dbg("[%s %d]Flags: %s\n",
                     __FILE__,__LINE__, s_flags);
   }
   
   msgStartPtr = tmp;
   if( conferencename_f::Matches(tmp,&c, start) )
   {
      memset(s_conferencename, 0, 32); 
      memcpy(s_conferencename, start+16, (tmp-start-18));
      line_print_dbg("[%s %d]ConferenceName: %s\n",
                     __FILE__,__LINE__, s_conferencename);
   }
   
   msgStartPtr = tmp;
   if( member_f::Matches(tmp,&c, start) )
   {
      memset(s_member, 0, 32); 
      memcpy(s_member, start+8, (tmp-start-10));
      line_print_dbg("[%s %d]Member:%s\n",__FILE__,__LINE__, s_member);
   }
   msgStartPtr = tmp;
   if( count_f::Matches(tmp,&c, start) )
   {
      memset(tbuff, 0, 32); 
      memcpy(tbuff, start+7, (tmp-start-9));
      i_count = atoi((char*)&tbuff);
      line_print_dbg("[%s %d]Count: %d\n",__FILE__,__LINE__, i_count);
   }
   msgStartPtr = tmp;
   if( key_f::Matches(tmp,&c, start) )
   {
      memset(tbuff, 0, 32); 
      memcpy(tbuff, start+5, (tmp-start-7));
      i_key = atoi((char*)&tbuff);
      line_print_dbg("[%s %d]Key: %d\n",__FILE__,__LINE__, i_key);
   }
   msgStartPtr = tmp;
   if( mute_f::Matches(tmp,&c, start) )
   {
      memset(tbuff, 0, 32); 
      memcpy(tbuff, start+6, (tmp-start-8));
      i_mute = atoi((char*)&tbuff);
      line_print_dbg("[%s %d]Mute: %d\n",__FILE__,__LINE__, i_mute);
   }
   msgStartPtr = tmp;
   if( member_f::Matches(tmp,&c, start) )
   {
      memset(s_member, 0, 32); 
      memcpy(s_member, start+8, (tmp-start-10));
      line_print_dbg("[%s %d]Member: %s\n",__FILE__,__LINE__, s_member);
   }
   msgStartPtr = tmp;
   if( callerid_f::Matches(tmp,&c, start) )
   {
      memset(s_callerid, 0, 32); 
      memcpy(s_callerid, start+10, (tmp-start-12));
      line_print_dbg("[%s %d]CallerID: %s\n",__FILE__,__LINE__, s_callerid);
   }
   msgStartPtr = tmp;
   if( calleridname_f::Matches(tmp,&c, start) )
   {
      memset(s_calleridname, 0, 32); 
      memcpy(s_calleridname, start+14, (tmp-start-16));
      line_print_dbg("[%s %d]CallerIDName: %s\n",__FILE__,__LINE__,s_calleridname);
   }
   msgStartPtr = tmp;
   if( state_f::Matches(tmp,&c, start) )
   {
      memset(s_state, 0, 32); 
      memcpy(s_state, start+7, (tmp-start-9));
      line_print_dbg("[%s %d]State: %s\n",__FILE__,__LINE__,s_state);
   }
   msgStartPtr = tmp;
   if( uniqueid_f::Matches(tmp,&c, start) )
   {
      memset(s_uniqueid, 0, 32); 
      memcpy(s_uniqueid, start+10, (tmp-start-12));
      line_print_dbg("[%s %d]UniqueID: %s\n",__FILE__,__LINE__,s_uniqueid);
   }

   msgStartPtr = tmp;
   if( duration_f::Matches(tmp,&c, start) )
   {
      memset(tbuff, 0, 32); 
      memcpy(tbuff, start+7, (tmp-start-9));
      i_duration= atoi((char*)&tbuff);
      line_print_dbg("[%s %d]Duration: %d\n",__FILE__,__LINE__,i_duration);
   }

   msgStartPtr = tmp;
   if( moderators_f::Matches(tmp,&c, start) )
   {
      memset(s_moderators, 0, 32); 
      memcpy(s_moderators, start+12, (tmp-start-14));
      line_print_dbg("[%s %d]Moderators: %s\n",__FILE__,__LINE__,s_moderators);
   }
   msgStartPtr = tmp;
   if( privilege_f::Matches(tmp,&c, start) )
   {
      memset(s_privilege, 0, 32); 
      memcpy(s_privilege, start+11, (tmp-start-13));
      line_print_dbg("[%s %d]Privilege: %s\n",
                     __FILE__,__LINE__, s_privilege);
   }
   msgStartPtr = tmp;
   if( message_f::Matches(tmp,&c, start) )
   {
      memset(s_message, 0, 128); 
      memcpy(s_message, start+9, (tmp-start-11));
      line_print_dbg("[%s %d]Message: %s\n",
                     __FILE__,__LINE__, s_message);
   }
   msgStartPtr = tmp;
   if( status_f::Matches(tmp,&c, start) )
   {
      memset(s_status, 0, 64); 
      memcpy(s_status, start+8, (tmp-start-10));
      line_print_dbg("[%s %d]Status: %s\n",
                     __FILE__,__LINE__, s_status);
   }
   return this;
}

ast_ami &ast_ami::operator=(const ast_ami &other)
{
    return *this;
}

int ast_ami::operator==(const ast_ami & other)
{
    return 0;
}
